
package multiNyID.MarkerModel;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Switch;

/**
 * class GridModel
 *
 * khusus untuk presentasi TA
 *
 * @author whe_green@yahoo.co.id
 * Analisis Metode Occlusion Based Pada Augmented Reality
 * Studi Kasus Interaksi dengan Objek Virtual Secara Realtime
 * Menggunakan Gerakan Tangan
 *
 * Institut Teknologi Telkom
 * Fakultas Informatika 2007
 * Bandung Indonesia
 *
 * nyargreen.wordpress.com
 */

public class SlideModel{

  private ManipulasiModel[] slideModel;
//  private ManipulasiModel cadangan;
  private BranchGroup slideBG;
//  private BranchGroup BG;
  
  private int pos;
  private int posMaks;
  private boolean bawah=false;
  private Switch visSwitch;
  
  public SlideModel(){
      posMaks = 0;
      pos = 0;
      slideModel = new ManipulasiModel[15];
      slideBG = new BranchGroup();
      slideBG.setCapability(BranchGroup.ALLOW_DETACH);
      slideBG.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
      slideBG.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);

          // create switch for model visibility
    visSwitch = new Switch();
    visSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    visSwitch.addChild( slideBG );
    visSwitch.setWhichChild( Switch.CHILD_ALL );   // make invisible
    
//    BG.addChild(visSwitch);
  }

  public ManipulasiModel getModel(int x){

      return slideModel[x];
  }

  public void addModel(ManipulasiModel model){
          
          slideModel[this.pos] = model;
          slideBG.addChild(getModel(this.pos).getModelBG());
          this.pos++;
          this.posMaks++;
          System.out.println(this.pos);
  }

  public void nextModel(){
      
  
      if (this.pos < posMaks-1)
      {
        getModel(this.pos).switchOn(Switch.CHILD_NONE);
        this.pos++;
        
      }
      else{
        this.pos=this.posMaks-1;
        getModel(this.pos).switchOn(Switch.CHILD_NONE);
        this.pos=0;

      }
      System.out.println(this.pos);
      getModel(this.pos).switchOn(Switch.CHILD_ALL);
  }

  

  public void createModel(BranchGroup bg, double skala){
      ManipulasiModel tempModel;
      tempModel= new ManipulasiModel(bg, skala);
      tempModel.switchOn(Switch.CHILD_NONE);
      addModel(tempModel);
  }
  public void createModel(String modelFnm, double skala, boolean hasOrd){
      ManipulasiModel tempModel;
      tempModel= new ManipulasiModel(modelFnm, skala, hasOrd);
      tempModel.switchOn(Switch.CHILD_NONE);
      addModel(tempModel);
  }

    public Switch getVisSwitch() {
        return visSwitch;
    }


    public void setSwitchOn(int i){
        visSwitch.setWhichChild(i);
    }


    public int getPosAwal() {
        return pos;
    }

    public int getPosAkhir() {
        return posMaks;
    }
    
    
}
